/*Copyright 2009-2010 by Ward, David J ( pymethius@ominian.net )
Licensed work, all rights reserved.*/
Ext.namespace("wm");
Ext.namespace("wmlib");

//I have forgotten what the hell this does
wmlib.mod_loader = function(targetContainer){
   self = this;
   var container = targetContainer;   
}

wmlib.sys_root = function () {
   var self = this;
      
   var startingBackground = {         
         region: "center",
         xtype: "panel",         
         autoLoad: "/content/sys_welcome.html"
      };
   
   
   var moduleMenu = new Ext.menu.Menu({
      items: []
   })
   
   var taskBar = new Ext.Panel({
      width: 120,
      region: "south",
      bbar: new Ext.ux.StatusBar({
        text: "Ready",
        iconCls: "ready-icon",
        statusAlign: 'right',
        items: [{                                    
           layout: "tbsplit", //It's a button, it's a menu, NO No It's a split menu button
           id: "moduleMenuButton",
           text: "Modules",
           menuAlign: "bl-tl?",
           menu: moduleMenu                                    
        }]
      })
     });
   
   var window = {
         id: "mainWindow",
         closable : false,
         layout: "border",         
         items: [startingBackground, taskBar]
   };   
   
   self.initialize = function(){
      new Ext.Viewport(window);      
      wm.sys = self; 
   }
         
   
      
   var applications = {};
   
   self.register = function(identifier, module){
      
      applications[identifier] = module;
      moduleMenu.add({
         text: identifier,
         handler : function(){
            //TODO add limiting logic to prevent an app being run 2x or more
            module.run()
         }
         });
      
        //tabPanel.add(panel)
   }
   
      
   
   self.initialize();
}

Ext.onReady(function(){
   wm.loader.notify("sys_root");
   new wmlib.sys_root(); 
});